<!-- src/main/resources/templates/home.html -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Home</title>
</head>
<body>
<!-- 使用安全导航操作符 ?. 防止null -->
<h1>Welcome, <span th:text="${user?.username}">Guest</span>!</h1>

<!-- 或者先检查user是否为null -->
<div th:if="${user != null}">
    <p th:text="'Hello, ' + ${user.username}"></p>
</div>

</body>
</html>